<template>
	<div class="hy-container">
		<HyTable :searchFields="searchFields" :searchConfig="searchConfig" :tableConfig="tableConfig" :tableColumns="tableColumns" ref="hyTableRef">
			<template #statusSlot="{ row }">
				<el-tag :class="setColor(row.processStatus)">{{ row.processStatusName }}</el-tag>
			</template>
			<template #operation>
				<el-table-column fixed="right" label="操作" width="75">
					<template #default="{ row }">
						<el-button text type="primary" icon="View" @click="handleView('approve', row)">查看</el-button>
					</template>
				</el-table-column>
			</template>
		</HyTable>
	</div>
</template>
<script lang="ts" setup>
import HyTable from '/@/components/HyTable/index.vue';
import { expertInfoPageApproveApi } from '/@/api/expertDatabase/expert';
import { useDict, useTreeDict } from '/@/hooks/dict';
import { useOperate } from '../hooks/useOperate';

const { industry_fields, process_status } = useDict('industry_fields', 'process_status');
const { expert_type } = useTreeDict('expert_type');
let { columns } = useOperate();

const tableColumns = computed(() => {
	let newColumns = [];
	newColumns = [...columns.slice(0, 7), { prop: 'rejectionFrequency', label: '拒绝次数', width: 100 }, ...columns.slice(7)];
	newColumns.push({ prop: 'processStatus', label: '状态', slot: 'statusSlot', width: 160, fixed: 'right' });
	return newColumns;
});
const tableConfig = computed(() => {
	return {
		request: expertInfoPageApproveApi,
	};
});
// 配置搜索
const searchFields = computed(() => {
	return {
		expertName: {
			type: 'input',
			label: '姓名',
		},
		processStatus: {
			type: 'select',
			label: '状态',
			options: process_status.value,
		},
		expertType: {
			type: 'cascader',
			label: '专家类别',
			options: expert_type.value,
			showAllLevels: true,
		},
		industryFields: {
			type: 'select',
			label: '擅长行业领域',
			options: industry_fields.value,
		},
	};
});
const searchConfig = computed(() => {
	return {
		labelWidth: '120px',
		type: 'search',
		title: '专家审核',
		show: true,
	};
});
//操作
const router = useRouter();
const hyTableRef = ref();
const handleView = (operateType: string, row: any) => {
	router.push({
		path: '/expertDatabase/expert/operate/index',
		query: {
			operateType,
			expertInfoId: row?.expertInfoId || '',
			processStatus: row?.processStatus || '',
			processInstanceId: row?.processInstanceId || '',
		},
	});
};

//设置颜色
const setColor = (type: number) => {
	switch (type) {
		case 1:
			return 'wait-tag';
		case 2:
			return 'agree-tag';
		case 3:
			return 'refuse-tag';
		default:
			break;
	}
};
</script>
<style scoped lang="scss"></style>
